package com.my.util.jdbc;

import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;

import org.logicalcobwebs.proxool.configuration.PropertyConfigurator;

public final class JdbcUtils {
	private JdbcUtils() {

	}

	static {
		try {
			Class.forName("org.logicalcobwebs.proxool.ProxoolDriver");
			Properties properties = new Properties();
			InputStream is = JdbcUtils.class.getClassLoader().getResourceAsStream("proxool.properties");
			properties.load(is);
			PropertyConfigurator.configure(properties);
		} catch (Exception e) {
			// throw new ExceptionInInitializerError(e);
			e.printStackTrace();
		}
	}

	//设置同步
	public static synchronized Connection getConnection() throws SQLException {
		return DriverManager.getConnection("proxool.sqlserver2008");
	}

	public static void free(ResultSet rs, Statement st, Connection conn) {
		try {
			if (rs != null) {
				rs.close();
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				if (st != null) {
					st.close();
				}
			} catch (Exception e) {
				e.printStackTrace();
			} finally {
				if (conn != null) {
					try {
						conn.close();
					} catch (Exception e) {
						e.printStackTrace();
					}
				}
			}
		}
	}
}
